<template>
  <div class="reportFormPage horizontal-border" v-if="show">
    <div class="report-dom horizontal">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">{{ this.form.baobmc }}</div>
        <div class="codeText">
          <tr v-for="(item, index) in form.baobbhList">
            {{
              item
            }}
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="160px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="30" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>

                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100" style="width: 15%" @blur="setHntqdhtfBgShiytj()" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100" style="width: 15%" @blur="setHntqdhtfBgShiytj()" />%RH
              </td>
            </tr>
            <tr>
              <td height="40" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="30" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="70px" class="middle-table">
          <tbody>
            <tr>
              <td>取样地点</td>
              <td>
                <el-input tabindex="200" v-model="form.quydd" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" />
              </td>
              <td>改性剂名称</td>
              <td>
                <el-input tabindex="200" v-model="form.gaixjmc" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" />
              </td>
              <td>改性沥青种类</td>
              <td>
                <el-input tabindex="200" v-model="form.gaixlqzl" @keydown.native="handleKeyDown($event, 0, 2)" :ref="'0_2'" />
              </td>
            </tr>
            <tr>
              <td>基质沥青产地</td>
              <td>
                <el-input tabindex="200" v-model="form.jizlqcd" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" />
              </td>
              <td>基质沥青种类</td>
              <td>
                <el-input tabindex="200" v-model="form.jizlqzl" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" />
              </td>
              <td>基质沥青标号</td>
              <td>
                <el-input tabindex="200" v-model="form.jizlqbh" @keydown.native="handleKeyDown($event, 1, 2)" :ref="'1_2'" />
              </td>
            </tr>
          </tbody>
        </table>
        <table height="290px" class="middle-table">
          <tbody>
            <tr>
              <td colspan="8">改性沥青弹性恢复试验(25℃)</td>
            </tr>
            <tr>
              <td rowspan="3">弹性恢复率(%)</td>
              <td>试样编号</td>
              <td>拉伸长度(cm)</td>
              <td>试样长度(cm)</td>
              <td>试样回缩后长度(cm)</td>
              <td>试样残留长度(cm)</td>
              <td>弹性恢复率测值(%)</td>
              <td>弹性恢复率(%)</td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.huifSybh1" @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifLscd1" @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifSycd1" @blur="calcHfz(1)" @keydown.native="handleKeyDown($event, 2, 2)" :ref="'2_2'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifSyhscd1" @keydown.native="handleKeyDown($event, 2, 3)" :ref="'2_3'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifClcd1" @blur="calcHfz(1)" @keydown.native="handleKeyDown($event, 2, 4)" :ref="'2_4'" />
              </td>
              <td>
                {{ form.huifCz1 }}
              </td>
              <td rowspan="2">
                {{ form.huifPjz }}
              </td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.huifSybh2" @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifLscd2" @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifSycd2" @blur="calcHfz(2)" @keydown.native="handleKeyDown($event, 3, 2)" :ref="'3_2'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifSyhscd2" @keydown.native="handleKeyDown($event, 3, 3)" :ref="'3_3'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.huifClcd2" @blur="calcHfz(2)" @keydown.native="handleKeyDown($event, 3, 4)" :ref="'3_4'" />
              </td>
              <td>
                {{ form.huifCz2 }}
              </td>
            </tr>
            <tr>
              <td colspan="8">改性沥青离析软化点差值</td>
            </tr>
            <tr>
              <td rowspan="5">软化点差值</td>
              <td>试样编号</td>
              <td>顶部沥青软化点r<sub>1</sub>（℃）</td>
              <td>底部沥青软化点r<sub>1</sub>（℃）</td>
              <td colspan="2">软化点差值 r<sub>1</sub>-r<sub>2</sub>△r（℃）</td>
              <td colspan="2">离析（℃）</td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.ruanhdSybh1" @keydown.native="handleKeyDown($event, 4, 0)" :ref="'4_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR11" @blur="calcRhd(1)" @keydown.native="handleKeyDown($event, 4, 1)" :ref="'4_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR21" @blur="calcRhd(1)" @keydown.native="handleKeyDown($event, 4, 2)" :ref="'4_2'" />
              </td>
              <td colspan="2">
                {{ form.ruanhdCz1 }}
              </td>
              <td rowspan="4" colspan="2">
                {{ form.ruanhdPjz }}
              </td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.ruanhdSybh2" @keydown.native="handleKeyDown($event, 5, 0)" :ref="'5_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR12" @blur="calcRhd(2)" @keydown.native="handleKeyDown($event, 5, 1)" :ref="'5_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR22" @blur="calcRhd(2)" @keydown.native="handleKeyDown($event, 5, 2)" :ref="'5_2'" />
              </td>
              <td colspan="2">
                {{ form.ruanhdCz2 }}
              </td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.ruanhdSybh3" @keydown.native="handleKeyDown($event, 6, 0)" :ref="'6_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR13" @blur="calcRhd(3)" @keydown.native="handleKeyDown($event, 6, 1)" :ref="'6_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR23" @blur="calcRhd(3)" @keydown.native="handleKeyDown($event, 6, 2)" :ref="'6_2'" />
              </td>
              <td colspan="2">
                {{ form.ruanhdCz3 }}
              </td>
            </tr>
            <tr>
              <td>
                <el-input tabindex="200" v-model="form.ruanhdSybh4" @keydown.native="handleKeyDown($event, 7, 0)" :ref="'7_0'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR14" @blur="calcRhd(4)" @keydown.native="handleKeyDown($event, 7, 1)" :ref="'7_1'" />
              </td>
              <td>
                <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.ruanhdR24" @blur="calcRhd(4)" @keydown.native="handleKeyDown($event, 7, 2)" :ref="'7_2'" />
              </td>
              <td colspan="2">
                {{ form.ruanhdCz4 }}
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="30px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left">
              <!-- {{this.form.jiancr}} -->
            </td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left">
              <!-- {{this.form.jilr}} -->
            </td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%">
              <!-- {{this.form.fuhr}} -->
            </td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-right: 30px">年</div>
              <div style="display: inline-block; margin-right: 30px">月</div>
              <div style="display: inline-block">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";
import { handleFocus, emptyConvert, calculateMeanvalue, handleKeyDown } from "@/views/reportForms/utils";
import { getLqnGxlqtxjlbBsInfo } from "@/api/report_lqn/lqn";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BaQjDetailView from "@/views/sycs/baQjDetail/BaQjDetailView.vue";
import TableLineLogChart from "@/views/reportForms/components/TableLineLogChart.vue";

export default {
  name: "gxlqtxjlb",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BaQjDetailView,
    TableLineLogChart
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      form: {
        detailList: [],
        baobbhList: []
      },
      show: false
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created() {
    this.init();
  },

  mounted() {
    // 传值碳化深度
    Bus.$on("setHntqdhtfjlbTanhsd", (data) => {
      data.forEach((item, index) => {
        this.form.detailList[index].shend = item;
      });
      this.setHntqdhtfBgTanhsd();
    });
  },
  beforeDestroy() {
    // 停止监听事件
    Bus.$off("setHntqdhtfjlbTanhsd");
  },
  methods: {
    // 根据报表id获取当前报表信息
    init() {
      this.show = false;
      getLqnGxlqtxjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        this.setInitialValue();
        if (!this.form.detailList || this.form.detailList.length <= 0) {
          this.getDetailList();
        }
        this.show = true;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    // 设置初始值
    setInitialValue() {
      if (this.form) {
        this.form.baobmc = this.form.baobmc || "改性沥青弹性恢复、离析试验检测记录表";
        this.form.baobbh = this.form.baobbh || "JGLQ10023,JGLQ10024";
        this.$set(this.form, "baobbhList", []);
        this.form.baobbhList = ["JGLQ10023", "JGLQ10024"];
      }
    },
    getDetailList() {
      this.$set(this.form, "detailList", []);
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setHntqdhtfBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setHntqdhtfBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },
    // 计算平均回弹值
    calculateHuitzPjz(index) {
      let arr = [];
      for (let i = 1; i <= 16; i++) {
        const element = this.form.detailList[index]["shiczRi" + i];
        if (element) {
          arr.push(element);
        } else {
          this.form.detailList[index]["shiczRi" + i] = null;
        }
      }
      let huitzPjz = null;
      if (arr.length == 16) {
        // 先排序
        arr.sort((a, b) => {
          return a - b;
        });
        // 去掉前三后三 取平均值
        arr.splice(0, 3);
        arr.splice(arr.length - 3, arr.length - 1);

        huitzPjz = calculateMeanvalue(arr, 1);
      }
      this.form.detailList[index].huitzPjz = huitzPjz;
      this.setHntqdhtfBgHuitzPjz();
    },
    // 给报告传值
    setHntqdhtfBgHuitzPjz() {
      const arr = this.form.detailList.map((item) => item.huitzPjz);
      Bus.$emit("setHntqdhtfBgHuitzPjz", arr);
    },
    // 传值碳化深度
    setHntqdhtfBgTanhsd() {
      const arr = this.form.detailList.map((item) => item.shend);
      Bus.$emit("setHntqdhtfBgTanhsd", arr);
    },
    // 传值试验条件
    setHntqdhtfBgShiytj() {
      const info = {
        shiytjwd: this.form.shiytjwd,
        shiytjsd: this.form.shiytjsd
      };
      Bus.$emit("setHntqdhtfBgShiytj", info);
    },
    submitForm() {
      return this.form;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    // 弹性恢复率测值
    calcHfz(type) {
      if (this.form["huifSycd" + type] && this.form["huifClcd" + type] && this.form["huifSycd" + type] != 0) {
        const a = decimal.subtract(this.form["huifSycd" + type], this.form["huifClcd" + type]);
        const b = decimal.multiply(a, 100);
        const c = decimal.divide(b, this.form["huifSycd" + type]);
        this.form["huifCz" + type] = c;
      } else {
        this.form["huifCz" + type] = null;
      }
      this.calcHfzPjz();
    },
    calcHfzPjz() {
      if (this.form.huifCz1 && this.form.huifCz2) {
        const a = decimal.add(this.form.huifCz1, this.form.huifCz2);
        const b = decimal.divide(a, 2);
        this.form.huifPjz = b;
      } else {
        this.form.huifPjz = null;
      }
      if (this.form.huifCz1 && !this.form.huifCz2) {
        this.form.huifPjz = this.form.huifCz1;
      }
      if (!this.form.huifCz1 && this.form.huifCz2) {
        this.form.huifPjz = this.form.huifCz2;
      }
      this.backBgzFun();
    },
    // 软化点差值
    calcRhd(type) {
      if (this.form["ruanhdR1" + type] && this.form["ruanhdR2" + type]) {
        const a = decimal.subtract(this.form["ruanhdR1" + type], this.form["ruanhdR2" + type]);
        this.form["ruanhdCz" + type] = a;
      } else {
        this.form["ruanhdCz" + type] = null;
      }
      this.calcRhdPjz();
    },
    calcRhdPjz() {
      let t = 0;
      let v = 0;
      if (this.form.ruanhdCz1) {
        t = decimal.add(t, this.form.ruanhdCz1);
        v = v + 1;
      }
      if (this.form.ruanhdCz2) {
        t = decimal.add(t, this.form.ruanhdCz2);
        v = v + 1;
      }
      if (this.form.ruanhdCz3) {
        t = decimal.add(t, this.form.ruanhdCz3);
        v = v + 1;
      }
      if (this.form.ruanhdCz4) {
        t = decimal.add(t, this.form.ruanhdCz4);
        v = v + 1;
      }
      if (v != 0) {
        const a = decimal.divide(t, v);
        if (a) {
          this.form.ruanhdPjz = a;
        } else {
          this.form.ruanhdPjz = null;
        }
      } else {
        this.form.ruanhdPjz = null;
      }
      this.backBgzFun();
    },
    // 返回报告引入值
    backBgzFun() {
      Bus.$emit("setLqnBgJiancjg", [
        { key: 139, value: this.form.huifPjz }, // 弹性恢复25℃
        { key: 140, value: this.form.ruanhdPjz } // 贮存稳定性离析,48h软化点差
      ]);
    },

    // 鼠标移动操作
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [2, 2, 4, 4, 2, 2, 2];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]?.length) {
        this.$refs[ref][0].focus();
      } else if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped></style>
